package mysql

import "gorm.io/gorm"

type House struct {
	gorm.Model
	UserId  int     `gorm:"type:int(11)" json:"userId,omitempty"`
	Title   string  `gorm:"type:varchar(30)" json:"title,omitempty"`
	Price   float64 `gorm:"type:decimal(10,2)" json:"price,omitempty"`
	Num     int     `gorm:"type:int(11)" json:"num,omitempty"`
	Info    string  `gorm:"type:varchar(50)" json:"info,omitempty"`
	Image   string  `gorm:"type:varchar(200)" json:"image,omitempty"`
	Examine int     `gorm:"type:int(11)" json:"examine,omitempty"`
	Status  int     `gorm:"type:int(11)" json:"status,omitempty"`
}

func (h *House) GetByUserId() error {
	return DB.Where("user_id = ?", h.UserId).Limit(1).Find(&h).Error
}
func (h *House) GetById() error {
	return DB.Where("id = ?", h.ID).Limit(1).Find(&h).Error
}
func (h *House) Create() error {
	return DB.Create(&h).Error
}
func (h *House) Update() error {
	return DB.Where("id = ?", h.ID).Updates(&h).Error
}

func (h *House) GetCreate_at() error {
	return DB.Where("user_id = ?", h.UserId).Order("created_at desc").Limit(1).Find(&h).Error
}
